<div class="row-fluid">
    <div class="box paint color_11">
        <div class="title">
            <h4> <span><?php echo __('Distribution'); ?></span> </h4>
        </div>
        <!-- End .title -->

        <div class="content top">
        <div class="alert">
            Média total dada pelos professores <?php echo $sum['before'] ?> <br />
            Média total atribuída pelos professores <?php echo $sum['after'] ?>
        </div>
<?php

if(isset($results))
{
	foreach ($results as $key => $teacher):
?>
<div class="row-fluid">
	<div class="span12" style="text-align: left;">
		<blockquote style="border-bottom: 1px solid #f5f5f5;">
			<p><h5 style="font-size: 36px;"><?php echo $teachers[$key]['Teacher']['name'] ?></h5></p>
		</blockquote>
	</div>
</div>
<div class="row-fluid">
    <div class="row-fluid box color_24 title_medium height_medium bar_stats paint_hover ">
      <div class="title">
      </div>
      <!-- End .title -->
      <div class="content row-fluid fluid numbers">
        <div class="span3 stats shown_left" style="margin-top: 20px; text-align: left;">
            <p>
            Peso médio dado: <?php echo $weightsBefore[$teachers[$key]['Teacher']['id']] ?><br />
            Peso médio atribuído: <?php echo $weightsAfter[$teachers[$key]['Teacher']['id']] ?><br />
            Carga Horária mínima 1º semestre: <?php echo $teachers[$key]['Teacher']['workload'] ?> horas<br />
            Carga Horária mínima 2º semestre: <?php echo $teachers[$key]['Teacher']['workload'] ?> horas<br />
            Carga Horária Adicional: <?php echo $teachers[$key]['Teacher']['additional_workload'] ?> horas<br />
          </p>
        </div>
        <div class="span3 shown_left hidden_phone">
          <div class="row-fluid fluid">
            <div class="span6">
              <div class="description">Atribuídas</div>
              <h2 class="value"><?php echo $teacher->workLoadTotalRgt-$teacher->getWorkloadRgt() ?> Horas</h2>
              <div class="progress small">
                <div class="bar white" style="width: 100%;"></div>
              </div>
              <div class="description">1º Semestre</div>
            </div>
            <div class="span6 full">
              <div class="description text_color_dark">Restam</div>
              <h2 class="value text_color_dark"><?php echo $teacher->getWorkloadRgt() ?> Horas</h2>
              <div class="progress small">
                <div class="bar " style="width: 0%;"></div>
              </div>
            </div>
          </div>
        </div>
        <div class="span3 shown_left hidden_phone">
          <div class="row-fluid fluid">
            <div class="span6">
              <div class="description">Atribuídas</div>
              <h2 class="value"><?php echo $teacher->workLoadTotalLft-$teacher->getWorkloadLft() ?> Horas</h2>
              <div class="progress small">
                <div class="bar white" style="width: 100%;"></div>
              </div>
              <div class="description">2º Semestre</div>
            </div>
            <div class="span6 full">
              <div class="description text_color_dark">Restam</div>
              <h2 class="value text_color_dark"><?php echo $teacher->getWorkloadLft() ?> Horas</h2>
              <div class="progress small">
                <div class="bar " style="width: 0%;"></div>
              </div>
            </div>
          </div>
        </div>
        <div class="span2 total_days" style="float:right; text-align:right">
          <div class="row-fluid">
            <div class="span6 total_clicks">
              <h1 class="value"><?php echo (($teacher->workLoadTotalLft-$teacher->getWorkloadLft()) + ($teacher->workLoadTotalRgt-$teacher->getWorkloadRgt()))/2 ?></h1>
              <div class="description mt15">Carga horária média</div>
            </div>
          </div>
        </div>
      </div>
      <!-- End .row-fluid --> 
      <!-- End .content --> 
    </div>
    <!-- End .box --> 
    
  </div>
<?php if(count($teacher->getDisciplines())) : ?>
	<table  class="responsive table table-striped table-bordered" style="margin-bottom: 30px;" id="<?php echo $teacher->getId(); ?>1">
        <thead>
            <tr>
                <th><?php echo __('Semester') ?></th>
                <th><?php echo __('Discipline') ?></th>
                <th><?php echo __('W. Sem.') ?></th>
                <th><?php echo __('W. Theoric') ?></th>
                <th><?php echo __('W. Practice') ?></th>
                <th><?php echo __('Team') ?></th>
                <th><?php echo __('Course') ?></th>
                <th><?php echo __('Weight') ?></th>
                <th><?php echo __('Ranking') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($teacher->getDisciplines() as $discipline): ?>
            <?php if($discipline->getSemester() == 1): ?>
	            <tr>
	                <td rel="semester"><?php echo $disciplines[$discipline->getId()]['Discipline']['semester'] ?>&nbsp;</td>
	                <td><a data-toggle="modal" href="#<?php echo $disciplines[$discipline->getId()]['Discipline']['id'] ?>" style="color:#ffffff; text-decoration: underline"><?php echo $disciplines[$discipline->getId()]['Team']['name'] ?></a>&nbsp;</td>
	                <td><?php echo $disciplines[$discipline->getId()]['Discipline']['total_workload'] ?>&nbsp;</td>
	                <td><?php echo $disciplines[$discipline->getId()]['Discipline']['theoretical_workload'] ?>&nbsp;</td>
	                <td><?php echo $disciplines[$discipline->getId()]['Discipline']['practice_workload'] ?>&nbsp;</td>
	                <td><?php echo $disciplines[$discipline->getId()]['Discipline']['team'] ?>&nbsp;</td>
                    <?php $courses = array(); ?>
                    <?php foreach ($disciplines[$discipline->getId()]['Courses'] as $course) : 
                        $courses[] = $course['acronym'];
                    endforeach; ?>
	                <td><?php echo implode(" + ", $courses) ?>&nbsp;</td>
	                <td rel="weight"><?php echo $teacher->getWeight($discipline->getId()) ?>&nbsp;</td>
                    <td><?php echo (isset($ranking[$teacher->getId()][$discipline->getId()]))?$ranking[$teacher->getId()][$discipline->getId()].'º':'Não possui'?>&nbsp;</td>
	            </tr>
        	<?php endif ?>
        <?php endforeach; ?>
        </tbody>
    </table>
    <table class="responsive table table-striped table-bordered" style="margin-bottom: 30px;" id="<?php echo $teacher->getId(); ?>2">
        <thead>
            <tr>
                <th><?php echo __('Semester') ?></th>
                <th><?php echo __('Discipline') ?></th>
                <th><?php echo __('W. Sem.') ?></th>
                <th><?php echo __('W. Theoric') ?></th>
                <th><?php echo __('W. Practice') ?></th>
                <th><?php echo __('Team') ?></th>
                <th><?php echo __('Course') ?></th>
                <th><?php echo __('Weight') ?></th>
                <th><?php echo __('Ranking') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($teacher->getDisciplines() as $discipline): ?>
            <?php if($discipline->getSemester() == 2): ?>
	            <tr>
	                <td rel="semester"><?php echo $disciplines[$discipline->getId()]['Discipline']['semester'] ?>&nbsp;</td>
	                <td><a data-toggle="modal" href="#<?php echo $disciplines[$discipline->getId()]['Discipline']['id'] ?>" style="color:#ffffff; text-decoration: underline"><?php echo $disciplines[$discipline->getId()]['Team']['name'] ?></a>&nbsp;</td>
	                <td><?php echo $disciplines[$discipline->getId()]['Discipline']['total_workload'] ?>&nbsp;</td>
	                <td><?php echo $disciplines[$discipline->getId()]['Discipline']['theoretical_workload'] ?>&nbsp;</td>
	                <td><?php echo $disciplines[$discipline->getId()]['Discipline']['practice_workload'] ?>&nbsp;</td>
	                <td><?php echo $disciplines[$discipline->getId()]['Discipline']['team'] ?>&nbsp;</td>
	                <?php $courses = array(); ?>
                    <?php foreach ($disciplines[$discipline->getId()]['Courses'] as $course) : 
                        $courses[] = $course['acronym'];
                    endforeach; ?>
                    <td><?php echo implode(" + ", $courses) ?>&nbsp;</td>
	                <td rel="weight"><?php echo $teacher->getWeight($discipline->getId()) ?>&nbsp;</td>
                    <td><?php echo (isset($ranking[$teacher->getId()][$discipline->getId()]))?$ranking[$teacher->getId()][$discipline->getId()].'º':'Não possui'?>&nbsp;</td>
	            </tr>
        	<?php endif ?>
        <?php endforeach; ?>
        </tbody>
    </table>
<?php else: ?>
	<table class="responsive table table-striped table-bordered" style="margin-bottom: 30px;" id="<?php echo $teacher->getId(); ?>1">
        <thead>
            <tr>
                <th><?php echo __('Semester') ?></th>
                <th><?php echo __('Discipline') ?></th>
                <th><?php echo __('W. Sem.') ?></th>
                <th><?php echo __('W. Theoric') ?></th>
                <th><?php echo __('W. Practice') ?></th>
                <th><?php echo __('Team') ?></th>
                <th><?php echo __('Course') ?></th>
                <th><?php echo __('Weight') ?></th>
                <th><?php echo __('Ranking') ?></th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
    <table class="responsive table table-striped table-bordered" style="margin-bottom: 30px;" id="<?php echo $teacher->getId(); ?>2">
        <thead>
            <tr>
                <th><?php echo __('Semester') ?></th>
                <th><?php echo __('Discipline') ?></th>
                <th><?php echo __('W. Sem.') ?></th>
                <th><?php echo __('W. Theoric') ?></th>
                <th><?php echo __('W. Practice') ?></th>
                <th><?php echo __('Team') ?></th>
                <th><?php echo __('Course') ?></th>
                <th><?php echo __('Weight') ?></th>
                <th><?php echo __('Ranking') ?></th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
<?php endif; ?>
<?php
	endforeach;
}
?>
<div class="row-fluid">
    <div class="span12" style="text-align: left;">
        <blockquote style="border-bottom: 1px solid #f5f5f5;">
            <p>Disciplinas não alocadas</p>
        </blockquote>
    </div>
</div>
<?php
if(isset($rest1))
{
?>

<table class="responsive table table-striped table-bordered" style="margin-bottom: 30px;" id="rest1">
    <thead>
            <tr>
                <th><?php echo __('Semester') ?></th>
                <th><?php echo __('Discipline') ?></th>
                <th><?php echo __('W. Sem.') ?></th>
                <th><?php echo __('W. Theoric') ?></th>
                <th><?php echo __('W. Practice') ?></th>
                <th><?php echo __('Team') ?></th>
                <th><?php echo __('Course') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($rest1 as $discipline): ?>
                <tr>
                    <td rel="semester"><?php echo $disciplines[$discipline->getId()]['Discipline']['semester'] ?>&nbsp;</td>
                    <td><a data-toggle="modal" href="#<?php echo $disciplines[$discipline->getId()]['Discipline']['id'] ?>" style="color:#ffffff; text-decoration: underline"><?php echo $disciplines[$discipline->getId()]['Team']['name'] ?></a>&nbsp;</td>
                    <td><?php echo $disciplines[$discipline->getId()]['Discipline']['total_workload'] ?>&nbsp;</td>
                    <td><?php echo $disciplines[$discipline->getId()]['Discipline']['theoretical_workload'] ?>&nbsp;</td>
                    <td><?php echo $disciplines[$discipline->getId()]['Discipline']['practice_workload'] ?>&nbsp;</td>
                    <td><?php echo $disciplines[$discipline->getId()]['Discipline']['team'] ?>&nbsp;</td>
                    <?php $courses = array(); ?>
                    <?php foreach ($disciplines[$discipline->getId()]['Courses'] as $course) : 
                        $courses[] = $course['acronym'];
                    endforeach; ?>
                    <td><?php echo implode(" + ", $courses) ?>&nbsp;</td>
                </tr>
        <?php endforeach; ?>
        </tbody>
</table>
<?php
}
if(isset($rest2))
{
?>
<table class="responsive table table-striped table-bordered" style="margin-bottom: 30px;" id="rest2">
    <thead>
            <tr>
                <th><?php echo __('Semester') ?></th>
                <th><?php echo __('Discipline') ?></th>
                <th><?php echo __('W. Sem.') ?></th>
                <th><?php echo __('W. Theoric') ?></th>
                <th><?php echo __('W. Practice') ?></th>
                <th><?php echo __('Team') ?></th>
                <th><?php echo __('Course') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($rest2 as $discipline): ?>
                <tr>
                    <td rel="semester"><?php echo $disciplines[$discipline->getId()]['Discipline']['semester'] ?>&nbsp;</td>
                    <td><a data-toggle="modal" href="#<?php echo $disciplines[$discipline->getId()]['Discipline']['id'] ?>" style="color:#ffffff; text-decoration: underline"><?php echo $disciplines[$discipline->getId()]['Team']['name'] ?></a>&nbsp;</td>
                    <td><?php echo $disciplines[$discipline->getId()]['Discipline']['total_workload'] ?>&nbsp;</td>
                    <td><?php echo $disciplines[$discipline->getId()]['Discipline']['theoretical_workload'] ?>&nbsp;</td>
                    <td><?php echo $disciplines[$discipline->getId()]['Discipline']['practice_workload'] ?>&nbsp;</td>
                    <td><?php echo $disciplines[$discipline->getId()]['Discipline']['team'] ?>&nbsp;</td>
                    <?php $courses = array(); ?>
                    <?php foreach ($disciplines[$discipline->getId()]['Courses'] as $course) : 
                        $courses[] = $course['acronym'];
                    endforeach; ?>
                    <td><?php echo implode(" + ", $courses) ?>&nbsp;</td>
                </tr>
        <?php endforeach; ?>
        </tbody>
</table>
<?php
}
?>
        </div>
        <!-- End .content --> 
    </div>
    <!-- End box --> 
</div>
<!-- End .row-fluid -->

<?php foreach ($disciplines as $key => $discipline): ?>
  <div id="<?php echo $discipline['Discipline']['id'] ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
      <h3 id="myModalLabel">Documentos</h3>
    </div>
    <div class="modal-body">
      <p><?php echo $this->Upload->view('Team', $discipline['Team']['id'], false, true); ?></p>
    </div>
    <div class="modal-footer">
      <button class="btn" data-dismiss="modal">Fechar</button>
    </div>
  </div>
<?php endforeach; ?>
